package com.example.lanouhn.bantangapp.activities.activities;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.example.lanouhn.bantangapp.R;

/**
 * Created by lanouhn on 16/7/26.
 */
public class Avatar_SingleProduct_Establish_Activity extends Activity {

    private ImageView back;//返回
    private TextView tv_complete;//完成
    private EditText et_title;//标题
    private EditText et_brief_introduction;//简介
    private ProgressBar progressbar; //转转转

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.avatar_singleproduct_establish_activity);
        back = (ImageView) findViewById(R.id.back);
        tv_complete = (TextView) findViewById(R.id.tv_complete);
        et_title = (EditText) findViewById(R.id.et_title);
        et_brief_introduction = (EditText) findViewById(R.id.et_brief_introduction);
        progressbar = (ProgressBar) findViewById(R.id.progressbar);
        initListener();

    }

    /**
     * 创建心愿单的   监听事件
     */
    private void initListener() {
        //返回
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        //标题
        et_title.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                if (et_title.getText().toString().trim().length() > 0) {
                    tv_complete.setTextColor(getResources().getColor(R.color.colorAccent));
                    tv_complete.setClickable(true);//设置完成按钮可以点击

                } else {
                    tv_complete.setTextColor(getResources().getColor(R.color.blank_gray));
                    tv_complete.setClickable(false);//设置完成按钮不能点击
                }

            }

            @Override
            public void afterTextChanged(Editable editable) {
                //发送创建成功的消息
                tv_complete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Toast.makeText(Avatar_SingleProduct_Establish_Activity.this, R.string.avatar_singleproduct_love_r, Toast.LENGTH_SHORT).show();
                        progressbar.setVisibility(View.VISIBLE);
                        finish();
                    }
                });
            }
        });
        //简介
        et_brief_introduction.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                if (et_title.getText().toString().trim().length() > 0 && et_brief_introduction.getText().toString().trim().length() > 0) {
                    tv_complete.setTextColor(getResources().getColor(R.color.colorAccent));
                    tv_complete.setClickable(true);//设置完成按钮可以点击
                } else {
                    tv_complete.setTextColor(getResources().getColor(R.color.blank_gray));
                    tv_complete.setClickable(false);//设置完成按钮不能点击

                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
                //发送创建成功的消息
                tv_complete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Toast.makeText(Avatar_SingleProduct_Establish_Activity.this, R.string.avatar_singleproduct_love_r, Toast.LENGTH_SHORT).show();
                        progressbar.setVisibility(View.VISIBLE);


                        finish();
                    }
                });

            }

        });
    }
}

